
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Tama_Chan.GameEngine_ns;
using Tama_Chan.Utils;


namespace Tama_Chan.Entities_ns
{
   public class Gateway : GameEntity
   {

      public Gateway(GameEngine gameEngine, Vector2 position)
      {
         GameEngine = gameEngine;
         Texture = GameEngine.SquareTexture;
         Position = position;
         Color = Color.OrangeRed;
         IntervalOne = GeneralUtils.GetSecondsAsTicks(5);
         Depth = GameEngine.GatewayTeleporterDepth;
         SoundOne = GameEngine.BloopSoundEffect.CreateInstance();
      }


      public override void Update(GameTime gameTime)
      {
         // If all Gateway entity types are maxed out, do nothing.
         if(GameEngine.FoodList.Count == GameEngine.MaxFood && GameEngine.EnemyList.Count == GameEngine.MaxEnemies)
         {
            return;
         }

         AccumulatedTicksOne += gameTime.ElapsedGameTime.Ticks;

         if(AccumulatedTicksOne > IntervalOne)
         {
            AccumulatedTicksOne = AccumulatedTicksOne - IntervalOne;

            if(GameEngine.EnemyList.Count < GameEngine.MaxEnemies)
            {
               Enemy enemy = new Enemy(GameEngine, new Vector2(Position.X, Position.Y));
               GameEngine.GameEntityList.Add(enemy);
               GameEngine.EnemyList.Add(enemy);
               SoundOne.Play();
					GameEngine.ParticleEngine.CreateSpawnEffect(gameTime, new Vector2(Position.X + Bounds.Width / 2f, Position.Y + Bounds.Height / 2f), Enemy.NormalColor);
            }
            else if(GameEngine.PowerPellet.State != PowerPelletState.Attacking && GameEngine.FoodList.Count < GameEngine.MaxFood)
            {
               Food food = new Food(GameEngine, new Vector2(Position.X, Position.Y));
               GameEngine.GameEntityList.Add(food);
               GameEngine.FoodList.Add(food);
               SoundOne.Play();
					GameEngine.ParticleEngine.CreateSpawnEffect(gameTime, new Vector2(Position.X + Bounds.Width / 2f, Position.Y + Bounds.Height / 2f), food.Color);
            }
         }

         base.Update(gameTime);
      }


      public override void Draw()
      {
         GameEngine.Game1.SpriteBatch.Draw(Texture, Position, null, Color, 0f, Vector2.Zero, Vector2.One, SpriteEffects.None, Depth);
         base.Draw();
      }

   }
}
